import 'package:flutter/material.dart';
import 'package:sharing/resources/code_point.dart';
import 'package:sharing/resources/strings.dart';
import 'package:sharing/resources/styles.dart';
import 'package:sharing/resources/dimens.dart';
import 'package:sharing/ui/component/full_with_button.dart';
import 'package:sharing/ui/my/my_content.dart';
import 'package:sharing/ui/my/create_book_list.dart';
import 'package:sharing/resources/colors.dart';
import 'package:sharing/ui/my/my_book_list.dart';
import 'package:sharing/ui/my/own_book_infos_widget.dart';

class MyPage extends StatefulWidget {
  MyPage({Key key}) : super(key: key);

  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _buildAppBar(context),
      body: _buildBody(context),
    );
  }

  // 构造 app bar
  AppBar _buildAppBar(BuildContext context) {
    return AppBar(
      backgroundColor: Colors.white,
      title: Text(IdString.myTitle, style: AppStyles.pageTitleTextStyle),
      elevation: Dimensions.appBarElevation,
      actions: <Widget>[
        IconButton(
          icon: Icon(Icons.add),
          color: AppColor.primary,
          onPressed: () {
            Navigator.of(context).push(
              MaterialPageRoute(
                builder: (context) {
                  return CreateBookListPage();
                },
              ),
            );
          },
        ),
      ],
    );
  }

  // 构造body
  Widget _buildBody(BuildContext context) {
    return Container(
      child: SingleChildScrollView(
        child: Column(
          children: _functions,
        ),
      ),
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    //   个人信息展示
    _functions.add(MyContent());

    // 我的收藏
    _functions.add(FullWithButton(
      iconPath: "assets/img/ic_collect.png",
      title: "我的收藏",
      onPressed: () {
        print("收藏....");
      },
    ));

    _functions.add(FullWithButton(
      iconPath: "assets/img/ic_collect.png",
      title: "我的书单",
      onPressed: (){
        Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => MyBookLists(),
        ),);
      },
    ));
    // 原创作品展示
    _functions.add(FullWithButton(
      iconPath: "assets/img/ic_origin.png",
      title: "原创",
      onPressed: () {
        print("原创");
        Navigator.of(context).push(MaterialPageRoute(builder: (context){
          return OwnBookInfosWidget();
        }));
      },
    ));

    // 推荐的作品
    _functions.add(FullWithButton(
      iconPath: "assets/img/ic_recommend.png",
      title: "推荐",
      onPressed: () {
        print("推荐");
      },
      showDivider: true,
    ));

    // 回复我的作品
    _functions.add(
      FullWithButton(
        iconPath: "assets/img/ic_reply_me.png",
        title: "回复我",
        onPressed: () {
          print("回复我");
        },
        num: "1",
        showDivider: true,
      ),
    );

    // 设置选项
    _functions.add(FullWithButton(
      iconPath: "assets/img/ic_setting.png",
      title: "设置",
      onPressed: () {
        print("设置");
      },
    ));
  }

  // list for the function
  List<Widget> _functions = [];
}
